package com.ostrich.shopping.ui.user.adapteer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.ostrich.shopping.R;
import com.ostrich.shopping.room.User;

import java.util.List;

/**
 * @Author : yaotianxue
 * @Time : On 2023/9/27 11:05
 * @Description : UserAdapter
 */
public class UserAdapter extends BaseAdapter {
    private Context mContext;

    public UserAdapter(Context context, List<User> userList) {
        mContext = context;
        mUserList = userList;
    }

    private List<User> mUserList;

    @Override
    public int getCount() {
        return mUserList.size();
    }

    @Override
    public Object getItem(int position) {
        return mUserList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_user, null);
            holder = new ViewHolder();
            holder.tvUsername = convertView.findViewById(R.id.tv_username);
            holder.tvDelete = convertView.findViewById(R.id.tv_delete);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvUsername.setText(mUserList.get(position).getNickname());
        return convertView;

    }
    class ViewHolder{
        TextView tvUsername,tvDelete;
    }
}
